package com.atguigu.java;

import org.junit.Test;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.Locale;

public class StringTest1 {
    @Test
    public void test1(){
        String str1="abc123";
        char[] charArray = str1.toCharArray();
        for (int i = 0; i < charArray.length; i++) {
            System.out.println(charArray[i]);

        }
        char[] arr = {'h', 'e', 'l', 'l', 'o'};
        String str2 = new String(arr);
        System.out.println(str2);

    }
    @Test
    public void test2() throws UnsupportedEncodingException {
        String str1="abc123理工";
        byte[] bytes = str1.getBytes();
        System.out.println(Arrays.toString(bytes));
        byte[] gbks = str1.getBytes("gbk");
        System.out.println(Arrays.toString(gbks));
        System.out.println("*******************");
        String str2 = new String(bytes);
        System.out.println(str2);
        String str3=new String(gbks);
        System.out.println(str3);
        String str4 = new String(gbks, "gbk");
        System.out.println(str4);

    }
}

